package tgc.edu.ljc.service;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tgc.edu.ljc.entity.Student;
import tgc.edu.ljc.repository.StudentRepsitory;

@Service
public class StudentService {
	@Autowired
	private StudentRepsitory studentDAO;

	public Student login(String username, String password) {
		return studentDAO.findByStuNumAndPassword(username,password);
	}

	public List<Student> findAll() {
		
		return studentDAO.findAll();
	}

	public Student findById(Integer id) {
		Optional<Student> optional = studentDAO.findById(id);
		if(optional.isPresent()) {
			return optional.get();
		}
		return null;
		//return studentDAO.findById(id).get();
	}

	public void save(Student model) {
		studentDAO.save(model);
	}
	
	
	
}
